﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YouHP.Model.Group
{
    public class GroupSearchCondition
    {
        public string GroupName { get; set; }
        public string DiseaseName { get; set; }      //疾病名称
        public int DiseaseId { get; set; }            //疾病id
        public string SymptomName { get; set; }     //症状名称
        public int SymptomId { get; set; }          //症状id
        public string TreatmentName { get; set; }   //治疗名称
        public int TreatmentId { get; set; }        //治疗id
        public int ProvinceId { get; set; }         //省份id
        public int CityId { get; set; }             //城市id

        public int OrderByField { get; set; }       //排序字段
        public const int USER_NUM = 1;              //成员总数
        public const int TOPIC_NUM = 2;             //话题数
        public const int HIT_NUM = 3;              //点击数
        public const int POST_NUM = 4;              //话题数+回复数



        public GroupSearchCondition()
        {
            GroupName = DiseaseName = SymptomName = TreatmentName = string.Empty;
            DiseaseId = SymptomId = TreatmentId = ProvinceId = CityId = -1;
        }


        public string ToSqlConditonString()
        {
            string sql = "[Group].[GroupType] = 0";

            if (GroupName.Length > 0)
            {
                sql += string.Format(" AND [Group].[GroupName] like '%{0}%'  ", GroupName);
            }

            if (DiseaseId > 0)
            {
                sql += string.Format("AND [Group].[DiseaseId] ={0}", DiseaseId);
            }

            if (SymptomId > 0)
            {
                sql += string.Format("AND [Group].[SymptomId] ={0}", SymptomId);
            }

            if (TreatmentId > 0)
            {
                sql += string.Format("AND [Group].[TreatmentId] ={0}", TreatmentId);
            }

            if (ProvinceId > 0)
            {
                sql += string.Format(" AND [Group].[ProvinceId] = {0} ", ProvinceId);
            }

            if (CityId > 0)
            {
                sql += string.Format(" AND [Group].[CityId] = {0} ", CityId);
            }

            return sql;
        }

        public string ToOrderByString()
        {
            string orderStr = "";

            switch (OrderByField)
            {
                case USER_NUM:
                    orderStr = " [Group].[UserNum] desc, [Group].[Hits] desc ";
                    break;
                case TOPIC_NUM:
                    orderStr = " [Group].[TopicNum] desc, [Group].[Hits] desc  ";
                    break;
                case POST_NUM:
                    orderStr = " [Group].[PostNum] desc, [Group].[Hits] desc  ";
                    break;
                case HIT_NUM:
                default:
                    orderStr = " [Group].[Hits] desc ";
                    break;
            }

            return orderStr;
        }
    }

}
